package com.luodea.lock.controller;

import com.luodea.lock.object.Car;
import com.luodea.lock.object.User;
import org.redisson.Redisson;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author luodea
 * @date 2020/2/27 14:38
 * @description redis 分布式对象测试
 */
@RestController
@RequestMapping("user")
public class TestController {

    @Autowired
    private RedissonClient redissonClient;


    private final String USER = "user";


    @GetMapping
    public User get(){
        RBucket<User> bucket = redissonClient.getBucket(USER);
        return bucket.get();
    }

    @PostMapping
    public String insert(){
        User user = new User();
        user.setId(UUID.randomUUID().toString());
        user.setName("luodea");
        user.setAge(45);
        Car car = new Car();
        car.setName("奥迪");
        car.setPrice(10000000);
        user.setCar(car);
        redissonClient.getBucket(USER).set(user);
        return "OK";
    }





}
